package com.example.tanlee.ocrgraduation.activity;

import android.content.Intent;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.tanlee.ocrgraduation.R;
import com.example.tanlee.ocrgraduation.application.MyApplication;

import cn.pedant.SweetAlert.SweetAlertDialog;


/**
 * write by tanlee 2017.1.18
 */
public class LoginActivity extends AppCompatActivity implements View.OnClickListener{

    private TextView loginBtn;

    private void initView(){
        loginBtn = (TextView) findViewById(R.id.login_btn);
    }

    private void setListener(){
           loginBtn.setOnClickListener(this);
    }

    private int countTemp = 0;
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.login_btn:
                showDialog();

                break;
            default:
                break;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initView();
        setListener();
    }

    private void showDialog(){
        final SweetAlertDialog pDialog = new SweetAlertDialog(this, SweetAlertDialog.PROGRESS_TYPE)
                .setTitleText("Loading");
        pDialog.show();
        pDialog.setCancelable(false);
        new CountDownTimer(800 * 4, 800) {
            public void onTick(long millisUntilFinished) {
                // you can change the progress bar color by ProgressHelper every 800 millis
                countTemp ++;
                switch (countTemp){
                    case 0:
                        pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.blue_btn_bg_color));
                        break;
                    case 1:
                        pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.material_deep_teal_50));
                        break;
                    case 2:
                        pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.success_stroke_color));
                        break;
                    case 3:
                        pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.material_deep_teal_20));
                        break;
//                    case 4:
//                        pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.material_blue_grey_80));
//                        break;
//                    case 5:
//                        pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.warning_stroke_color));
//                        break;
//                    case 6:
//                        pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.success_stroke_color));
//                        break;
                }
            }

            public void onFinish() {
                pDialog.setTitleText("Update Success!")
                        .setConfirmText("OK")
                        .changeAlertType(SweetAlertDialog.SUCCESS_TYPE);
                MyApplication.getInstance().count ++;
                Intent intent = new Intent(LoginActivity.this,MainActivity.class);
                startActivity(intent);
//                if(MyApplication.getInstance().count / 2 == 0){
//                    processTimeTxt.setText(StringConstant.PROCESS_TIME + "5.1s");
//                    processResultTxt.setText(StringConstant.RESULT_STRING1);
//                }
//                else {
//                    processResultTxt.setText(StringConstant.RESULT_STRING2);
//                    processTimeTxt.setText(StringConstant.PROCESS_TIME + "4.3s");
//                }
//                processState.setText(StringConstant.PROCESS_STATUS + "已处理");
            }
        }.start();
    }
}
